<template>
  <div class="content">
    <div class="card_header">告警中心</div>

    <div class="card_table">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="日历报警" name="1">
          <div class="card_form" style="margin-bottom:0px ;">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
              <el-form-item label="日期范围">
                <el-date-picker
                  v-model="formInline.date"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :icon="Search" @click="onSubmit"
                  >查询</el-button
                >
                <el-button type="default" :icon="Refresh" @click="onSubmit"
                  >重置</el-button
                >
              </el-form-item>
            </el-form>
          </div>
          <div
            style="display: flex; justify-content: space-between; align-items: flex-start"
          >
            <el-calendar style="width: 85%">
              <template #date-cell="{ data }">
                <p :class="data.isSelected ? 'is-selected' : ''">
                  {{ data.day.split("-").slice(1).join("-") }}
                  {{ data.isSelected ? "✔️" : "" }}
                </p>
              </template> </el-calendar
            ><el-table
              :data="tableData"
              style="width: 330px"
              :default-sort="{ prop: 'date', order: '0' }"
              border
              stripe
              height="540"
            >
              <el-table-column label="报警描述" prop="smartID" align="center" sortable>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="报警明细" name="2">
          <div class="card_form">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
              <el-form-item label="状态">
                <el-select v-model="value" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="日期范围">
                <el-date-picker
                  v-model="formInline.date"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :icon="Search" @click="onSubmit">查询</el-button
                ><el-button type="success" :icon="Search" @click="onSubmit"
                  >导出</el-button
                >
                <el-button type="default" :icon="Refresh" @click="onSubmit"
                  >重置</el-button
                >
              </el-form-item>
            </el-form>
          </div>
          <el-table
            :data="tableData"
            style="width: 100%"
            :default-sort="{ prop: 'date', order: 'descending' }"
            border
            stripe
            height="450"
          >
            <el-table-column
              label="报警标题"
              prop="group"
              align="center"
              width="120"
              sortable
            />
            <el-table-column
              label="报警描述"
              prop="smartID"
              align="center"
              width="310"
              sortable
            >
            </el-table-column>
            <el-table-column
              label="报警类型"
              prop="magnification"
              align="center"
              sortable
            />
            <el-table-column label="状态" sortable align="center">
              <template #default="scope">
                <div v-if="scope.row.status == 0">
                  <el-tag type="info">离线</el-tag>
                </div>
                <div v-if="scope.row.status == 1">
                  <el-tag type="success">在线</el-tag>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="备注" prop="attribute" align="center" sortable />
            <el-table-column
              label="报警发生时间"
              prop="communicationDate"
              align="center"
              sortable
              width="200"
            />
            <!-- <el-table-column fixed="right" label="操作" width="100" align="center">
              <template #default>
                <el-button link type="primary" size="small" @click="onDetail">
                  详情
                </el-button>
              </template>
            </el-table-column> -->
          </el-table>
          <div style="width: 30%; position: absolute; bottom: 30px; right: 80px">
            <el-pagination background layout="prev, pager, next" :total="100" />
          </div>
        </el-tab-pane>
        <el-tab-pane label="报警统计" name="3">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="年份">
              <el-date-picker
                v-model="formInline.date"
                type="year"
                placeholder="选择年"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" :icon="Search" @click="onSubmit">查询</el-button>
              <el-button type="default" :icon="Refresh" @click="onSubmit">重置</el-button>
            </el-form-item>
          </el-form>
          <div
            style="display: flex; justify-content: space-between; align-items: flex-start"
          >
            <div style="width: 80%"><MonthBarChart /><DeviceStatusPieChart /></div>
            <div style="width: 15%">
              <el-table
                :data="tableDataYear"
                style="width: 330px"
                :default-sort="{ prop: 'date', order: 'descending' }"
                border
                stripe
              >
                <el-table-column label="年份" prop="year" align="center" sortable />
                <el-table-column label="发生次数" prop="total" align="center" sortable />
              </el-table>
              <el-table
                :data="tableDataTotal"
                style="width: 330px"
                :default-sort="{ prop: 'date', order: 'descending' }"
                border
                stripe
              >
                <el-table-column label="报警类型" prop="type" align="center" sortable>
                </el-table-column>
                <el-table-column label="发生次数" prop="total" align="center" sortable>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup>
import { Search, Refresh } from "@element-plus/icons-vue";
import { ref, reactive } from "vue";
import MonthBarChart from "@/components/MonthBarChart.vue";
import DeviceStatusPieChart from "../../../components/DeviceStatusPieChart.vue";

const formInline = reactive({
  user: "",
  region: "",
  date: "",
});
const detailShow = ref(false);
const activeName = ref("1");
const tableData = ref([
  {
    electricID: "001",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "1",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线电话预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "002",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "1",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线电话预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "003",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "0",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线电话预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "003",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "0",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线微信预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "003",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "0",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线电话预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "003",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "0",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线微信预警",
    communicationDate: "2025-02-06 16:34:33",
  },
  {
    electricID: "003",
    group: "设备离线报警",
    smartID: "该设备已下线，发生预警，工作人员及时处理",
    magnification: "离线电话预警",
    capacity: "0",
    status: "0",
    purpose: "2层-211",
    name: "青澜青云",
    number: "2ALZ22",
    countType: "统一电量",
    attribute: "下线电话预警",
    communicationDate: "2025-02-06 16:34:33",
  },
]);
const tableDataYear = ref([
  {
    year: "1月",
    total: "100",
  },
  { year: "2月", total: "200" },
  { year: "3月", total: "300" },
  { year: "4月", total: "400" },
  { year: "5月", total: "500" },
  { year: "6月", total: "600" },
  { year: "7月", total: "700" },
  { year: "8月", total: "800" },
  { year: "9月", total: "900" },
  { year: "10月", total: "1000" },
  { year: "11月", total: "1100" },
  { year: "12月", total: "1200" },
]);
const tableDataTotal = ref([
  {
    type: "离线",
    total: "100",
  },
  {
    type: "在线",
    total: "200",
  },
  {
    type: "故障",
    total: "300",
  },
]);
// 详情
const onDetail = () => {
  detailShow.value = !detailShow.value;
};
</script>
<style lang="less" scoped>
li {
  list-style: none;
}
.content {
  box-shadow: 0px 0px 8px rgba(0.1, 0.1, 0.1, 0.3);
  border-radius: 10px;
}
.card_header {
  background: linear-gradient(
    90deg,
    #409eff,
    rgba(44, 166, 224, 0.2),
    rgba(44, 166, 224, 0)
  );
  border-top-right-radius: 10px;
  border-top-left-radius: 10px;
  padding: 15px 20px;
  color: #fff;
}
.card_form {
  // width: 80%;
  padding: 20px 20px;
  // padding-top: 40px;
  margin-bottom: 20px;
}
.demo-form-inline {
  .el-input {
    --el-input-width: 220px;
  }
  .el-select {
    --el-select-width: 160px;
  }
}
.card_table {
  padding: 40px 20px;
  position: relative;
}
.card_box {
  box-shadow: 0px 0px 8px rgba(0.1, 0.1, 0.1, 0.3);
  border-radius: 10px;
  margin-bottom: 25px;
}
.card_box_descriptions {
  padding: 15px;
}
.log > li {
  margin-bottom: 15px;
}
:deep(.el-table__header .el-table__cell) {
  background: #409eff !important;
  color: #fff;
}
:deep(.el-table .ascending .sort-caret.ascending) {
  border-bottom-color: #fff !important;
}
:deep(.el-table .descending .sort-caret.descending) {
  border-top-color: #fff !important;
}
:deep(.el-table__row td:first-child:hover) {
  color: #409eff;
  cursor: pointer;
}
:deep(.el-form) {
  height: 45px;
}
:deep(.el-drawer__header) {
  margin-bottom: 0;
}
.is-selected {
  color: #1989fa;
}
</style>
